package com.qianfeng1.day7_连接池;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.*;

/**
 * 作者：黎杭
 * 日期：2020/2/18
 * <p>
 * 错误代码示例
 */
public class Test {
    public static void main(String[] args) throws ParseException, ExecutionException, InterruptedException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse = simpleDateFormat.parse("2020-02-18");
        System.err.println(parse);

        ExecutorService executorService = Executors.newCachedThreadPool();// 创建一个缓冲的线程池
        Callable<Date> callable = () -> simpleDateFormat.parse("2020-02-18");

        List<Future<Date>> list = new ArrayList<>();
        for (int x = 0; x < 10; x++) {
            Future<Date> submit = executorService.submit(new Callable<Date>() {
                @Override
                public Date call() throws Exception {
                    return simpleDateFormat.parse("2020-02-18");


                }
            });// 此时会得到FutureTask对象
            list.add(submit);
        }
        for (Future<Date> f : list) {
            Date date = f.get();// 获取线程最后返回的日期
            System.err.println(date);
        }

    }
}
